package com.uni.exp5.aspect;

import com.uni.exp5.pojo.Equip;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * Author:      Unirithe/Mr.Chao
 * CSDN:        https://blog.csdn.net/Unirithe
 * CreatedTime:  2022/1/20 13:33
 **/
@Component
@Aspect
public class BeforeUpdateEquip {
    @Pointcut("execution(public * com.uni.exp5.pojo.Player.updateEquip(..))")
    public void pointcut(){}
    // 环绕增强
    @Around("pointcut()")
    public void afterUpdateEquip(JoinPoint jp){
        // 根据方法获取增强后的装备
        Equip equip = (Equip) jp.getArgs()[0];
        // 如果是指环装备那么则提升属性
        if("指环".equals(equip.getType())){
            equip.setName("紫色梦幻" + equip.getName());
            equip.setAttackPlus(equip.getAttackPlus() + 6);
            equip.setDefencePlus(equip.getDefencePlus() + 6);
        } else System.out.println("非指环类装备");
    }
}
